/* eslint-disable */
import request from "@/request";

/** uploadFile POST /api/api/file/upload */
export async function uploadFileUsingPost(
  body: {},
  file?: File,
  options?: { [key: string]: any }
) {
  const formData = new FormData();

  if (file) {
    formData.append("file", file);
  }

  Object.keys(body).forEach((ele) => {
    const item = (body as any)[ele];

    if (item !== undefined && item !== null) {
      if (typeof item === "object" && !(item instanceof File)) {
        if (item instanceof Array) {
          item.forEach((f) => formData.append(ele, f || ""));
        } else {
          formData.append(ele, JSON.stringify(item));
        }
      } else {
        formData.append(ele, item);
      }
    }
  });

  return request<API.BaseResponseString_>("/api/api/file/upload", {
    method: "POST",
    data: formData,
    // requestType: "form",
    ...(options || {}),
  });
}

/** uploadFiles POST /api/api/file/upload/batch */
export async function uploadFilesUsingPost(
  body: {
    /** files */
    files: any[];
  },
  options?: { [key: string]: any }
) {
  return request<API.BaseResponseListString_>("/api/api/file/upload/batch", {
    method: "POST",
    headers: {
      "Content-Type": "application/x-www-form-urlencoded",
    },
    data: body,
    ...(options || {}),
  });
}
